/*
 * Ganesa Copyright (C) 2008 Wim Crols <twimpiex@gnx.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package be.gnx.ganesa.application.controller;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

import be.gnx.ganesa.application.command.Command;
import be.gnx.ganesa.application.model.Application;
import be.gnx.ganesa.application.model.Project;
import be.gnx.ganesa.application.ui.Ganesa;
import be.gnx.ganesa.application.ui.dialog.ImportDialog;
import be.gnx.ganesa.application.ui.dialog.ImportDialog.ImportDialogResult;

public class Import implements SelectionListener {

  private Ganesa ganesa;

  public Import(Ganesa ganesa) {
    this.ganesa = ganesa;
  }

  public void widgetDefaultSelected(SelectionEvent selectionEvent) {
    Import.this.widgetSelected(selectionEvent);
  }

  public void widgetSelected(SelectionEvent selectionEvent) {
    ImportDialog importDialog = new ImportDialog(selectionEvent.display.getActiveShell());
    importDialog.setText("Import");
    ImportDialogResult importDialogResult = importDialog.open();
    Application application = ganesa.getApplication();
    Project project = application.getSelectedProject();
    project.setZoomBox(importDialogResult.boundingBoxTabItemControl.getBoundingBox());
    Command command = importDialogResult.importPlugin.newImportCommand(ganesa.getApplication(), importDialogResult);
    command.execute();
  }

}
